package active

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"gm/app/controller/base"
	"gm/app/service/active"
	error2 "gm/app/util/error"
	"gm/app/util/response"
	"log"
	"strconv"
	"time"
)

type ActiveController struct {
	base.BaseController
	activeService active.ActiveService
}

func (this *ActiveController) GetActiveLeftMoney(c *gin.Context) {
	actid, err := strconv.Atoi(c.Query("actid")) //活动类型ID
	if err != nil {
		c.JSON(200, gin.H{
			"code":      -1,
			"data":      actid,
			"msg":       err.Error(),
			"timestamp": time.Now().Unix(),
		})
		return
	}

	if actid == 0 {
		fmt.Printf("参数不能为空\n" )
		error2.ErrorNew("参数不能为空")  //日志

		utilGin := response.Gin{Ctx: c}
		utilGin.Response(-1, "参数不能为空", nil)
		return
	}

	res, err := this.activeService.GetData(actid)
	//$week_money = ActivemanageLogic::getInstance()->getWeekMoney($this->chatroomid, $actid); //周普通活动资金
	c.JSON(200, gin.H{
		"code":      200,
		"data":      res,
		"msg":       "success",
		"timestamp": time.Now().Unix(),
	})

}

func (this *ActiveController) GetList(c *gin.Context) {
	log.Fatal("Server Shutdown:", 123)
	cid :=157
	res,err := this.activeService.GetActives(cid)
	if err != nil {
		c.JSON(200, gin.H{
			"code":      500,
			"data":      res,
			"msg":       err.Error(),
			"timestamp": time.Now().Unix(),
		})
		return
	}


	go func() {  //异步处理发邮件/发短信等
		fmt.Println(23)
	}()

	c.JSON(200, gin.H{
		"code":      200,
		"data":      res,
		"msg":       "success",
		"timestamp": time.Now().Unix(),
	})

}

func (this *ActiveController) Active(c *gin.Context) {

	cid :=157
	res,_ := this.activeService.GetActives(cid)
	c.JSON(200, gin.H{
		"code":      200,
		"data":      res,
		"msg":       "success",
		"timestamp": time.Now().Unix(),
	})

}